package com.huzz.util.body;

/**
 * 返回体构造工具
 *
 * @author 童年的纸飞机
 */
public class ResultTool {

    public static JsonResult success() {
        return new JsonResult(true);
    }

    public static <T> JsonResult<T> response(DataBox<T> dataBox) {
        return dataBox.isSucceed() ? new JsonResult(true, dataBox.data()) : new JsonResult(false, dataBox.data());
    }

    public static <T> JsonResult<T> success(T data) {
        return new JsonResult(true, data);
    }

    public static JsonResult success(int statusCode, String message) {
        return new JsonResult(true, statusCode, message);
    }

    public static JsonResult fail() {
        return new JsonResult(false);
    }

    public static JsonResult fail(ResultCode resultEnum) {
        return new JsonResult(false, resultEnum);
    }

    public static JsonResult fail(String text) {
        return new JsonResult(false, text);
    }

    public static JsonResult fail(int statusCode, String message) {
        return new JsonResult(false, statusCode, message);
    }

}